package com.shujia.wyh.day24;

import java.io.*;

/*
        将D盘下的MainDemo.java复制到E盘下MainDemo2.java
        数据源：D:\\MainDemo.java -- 字符输入流 -- Reader -- InputStreamReader
        目的地：E:\\MainDemo2.java -- 字符输出流 -- Writer -- OutputStreamWriter
 */
public class CopyFileDemo6 {
    public static void main(String[] args) throws IOException {
        //创建字符输入流对象
        InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\MainDemo.java"));
        //创建字符输出流对象
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\MainDemo3.java"));

        //一次读写一个字符
//        int ch = 0;
//        while ((ch = isr.read()) != -1){
//            osw.write(ch);
//            osw.flush();
//        }
//        System.out.println("文件复制完毕！");
        System.out.println("=================================");
        //一次读写一个字符数组
        char[] chars = new char[1024];
        int length = 0;
        while ((length = isr.read(chars)) != -1) {
            osw.write(chars, 0, length);
            osw.flush();
        }
        System.out.println("文件复制完毕！");


        //释放资源
        osw.close();
        isr.close();

    }
}
